<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getRandom(m, n) {
            return parseInt(Math.random() * (n - m) + m)
        }
        function game() {
            var n = getRandom(1, 10)
            while (true) {
                var a = prompt("请输入数字")
                a = parseInt(a)
                if (a == n) {
                    alert("猜对了")
                    break
                } else if (a < n) {
                    alert("猜小了")
                } else if (a > n) {
                    alert("猜大了")
                }
            }
        }
        game()
    </script>
</body>

</html>